package homework;

import java.text.DecimalFormat;
import java.util.Arrays;
import java.util.Scanner;

public class Day06标准练习 {
    public static double[] inputData(){
        Scanner scanner = new Scanner(System.in);
        System.out.println("请输入评委人数：");
        int n = scanner.nextInt();
        double[] scores = new double[n];
        for (int i = 0; i <n; i++) {
            System.out.println("请输入第"+(i+1)+"位评委的分数：");
            double score = scanner.nextDouble();
            scores[i] = score;
        }
        return scores;
    }
    public static String calculateArray(double[] scores){
        Arrays.sort(scores);
        double max = scores[scores.length-1];
        double min = scores[0];
        int maxCount=1;
        int minCount=1;
        for (double num:scores){
            if (num==max){
               maxCount++;
            } else if (num==min) {
                minCount++;
            }
        }
        double sum = 0;
        for (double num:scores){
            sum+=num;
        }
        double average =(sum-maxCount*max-minCount*min)/(scores.length-maxCount-minCount);
        DecimalFormat df = new DecimalFormat("#.00");
        return df.format(average);
    }
    public static void main(String[] args) {
        //需求:<<主持人大赛>>有N位评委给选手打分-选手的最终得分为:去掉最高分和最低分之后的N-2位评委的平均分,要求:使用方法实现
        double[] scores = inputData();
        String average = calculateArray(scores);
        System.out.println(average);
        //完成猜数字小游戏,要求：使用while(true)自造死循环实现
        int num = (int)(Math.random()*100);
        Scanner scanner = new Scanner(System.in);
        while (true){
            System.out.println("猜：");
            int guessing = scanner.nextInt();
            if (guessing>num){
                System.out.println("大了");
            } else if (guessing<num) {
                System.out.println("小了");
            }else {
                System.out.println("对了");
                break;
            }
        }
    }
}
